require(['./config'], () => {
    require(['header', 'footer', 'cookie'], (header) => {
      class Registered {
        constructor () {
          this.input()
        }
        input(){
          $('#sub').on('click',function(){
            var phone = $('#phone').val()
            var loginpwd = $('#loginpwd').val()
            var loginPwd = $('#loginPwd').val()

            if(loginpwd === loginPwd && loginpwd !== '' && loginPwd !== '' && phone !== ''){
              let user = localStorage.getItem('user')
              if(user){
                user = JSON.parse(user)
                const isExist = user.some(name => {
                  return name.phone === phone
                })
                if(isExist){
                  $('#warning span').html('用户已存在')
                  $('#warning').show()
                  setTimeout(function(){
                    $('#phone').val('')
                    $('#loginpwd').val('')
                    $('#loginPwd').val('')
                    $('#warning').hide()
                  },1000)
                }else{
                  user.push({ phone,loginpwd })
                  localStorage.setItem('user', JSON.stringify(user))
                  $('.register b').show()
                  setTimeout(function(){
                    $('.register b').hide()
                    $.cookie('name', phone, { expires: 3, path: '/' })
                    header.userName()
                    location.href = '/index.html'
                  },1000)
                }
              }
              else{
                localStorage.setItem('user', JSON.stringify([{
                  phone,loginpwd
                }]))
                $('.register b').show()
                setTimeout(function(){
                  $('.register b').hide()
                  $.cookie('name', phone, { expires: 3, path: '/' })
                  header.userName()
                  location.href = '/index.html'
                },1000)
              }
            }else{
              if(loginpwd == '' || loginPwd == '' || phone == ''){
                $('#warning span').html('账号密码输入不全')
                $('#warning').show()
                setTimeout(function(){
                  $('#warning').hide()
                },1000)
              }else{
                $('#warning span').html('密码输入不一致')
                $('#warning').show()
                setTimeout(function(){
                  $('#phone').val('')
                  $('#loginpwd').val('')
                  $('#loginPwd').val('')
                  $('#warning').hide()
                },1000)
              }
            }

          })
          
        }

      }
      new Registered()
    })
})